home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************************
- *
- *
- * ObjectMacZapp -- a standard Mac OOP application template
- *
- *
- *
- * ZWindowManager.cpp -- desktop class handles floaters
- *
- *
- *
- *
- *
- * © 1996, Graham Cox
- *
- *
- *
- *
- *************************************************************************************************/
-
-
- #include "ZObjectArray.cpp"
-
- #include "MacZoop.h"
- #include "ZWindow.h"
- #include "ZDialog.h"
- #include "ZEventHandler.h"
-
-
- ZWindowManager* gWindowManager = NULL;
-
-
- /*--------------------------------*** CONSTRUCTOR ***---------------------------------*/
-
- ZWindowManager::ZWindowManager()
- {
- // make the lists
-
- FailNIL( nonFloaters = new ZWindowList());
- FailNIL( floaters = new ZWindowList());
-
- wmWindows = NULL;
- wmMenu = NULL;
- wmItemOffset = 0;
-
- // set up member for controlling window placement
-
- globalPlaceLoc.h = 2;
- globalPlaceLoc.v = GetMBarHeight() + 2;
-
- // we are the only one, and we are global
-
- gWindowManager = this;
- }
-
- /*---------------------------------*** DESTRUCTOR ***---------------------------------*/
-
-
- ZWindowManager::~ZWindowManager()
- {
- if ( nonFloaters )
- ForgetObject( nonFloaters );
-
- if ( floaters )
- ForgetObject( floaters );
-
- if ( wmWindows )
- ForgetObject( wmWindows );
- }
-
-
- /*---------------------------------*** ADDWINDOW ***----------------------------------*/
- /*
- add the window to the relevant list of windows, and set its initial (Z) position
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::AddWindow( ZWindow* aWindow )
- {
- FailNILParam( aWindow );
-
- // determine if this window is a floater or not:
-
- if ( aWindow->Floats())
- {
- ZWindow* zw = GetBottomFloater();
-
- BringBehind( aWindow, zw );
- floaters->AppendItem( aWindow );
- }
- else
- {
- SendBehind( aWindow->GetMacWindow(), NULL );
- nonFloaters->AppendItem( aWindow );
-
- // if we're maintaining a "Windows" menu, append the window to our list if
- // it non-floating and not a modal dialog box.
-
- Boolean eligibleWindow;
-
- eligibleWindow = ( ! IsDialog( aWindow )) ||
- ( IsDialog( aWindow ) && ! ((ZDialog*) aWindow )->IsModal());
-
- if ( wmWindows && eligibleWindow )
- wmWindows->AppendItem( aWindow );
-
- BuildWindowsMenu();
- }
- }
-
-
- /*--------------------------------*** REMOVEWINDOW ***--------------------------------*/
- /*
- remove the window from the relevant list; make sure the next window is activated correctly.
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::RemoveWindow( ZWindow* aWindow )
- {
- FailNILParam( aWindow );
-
- ZWindow* zw;
-
- if ( aWindow->Floats())
- {
- floaters->DeleteObject( aWindow );
-
- // next window in layer needs to be activated to maintain our list
-
- zw = GetTopFloater();
-
- if ( zw )
- PostActivation( zw, TRUE );
- }
- else
- {
- nonFloaters->DeleteObject( aWindow );
-
- if ( wmWindows )
- wmWindows->DeleteObject( aWindow );
-
- // next window in layer needs to be activated to maintain our list
-
- zw = GetTopWindow();
-
- if ( zw )
- PostActivation( zw, TRUE );
-
- BuildWindowsMenu();
-
- // if all windows closed, reset global positioning variable
-
- if ( CountWindows() == 0 )
- {
- globalPlaceLoc.h = 2;
- globalPlaceLoc.v = GetMBarHeight() + 2;
- }
- }
- }
-
-
- /*-------------------------------*** INITIALLYPLACE ***-------------------------------*/
- /*
- Call this after creating a window to place it initially. By default, this will stack the
- windows from top left towards bottom right, taking into account their correct title bar
- heights, etc. Override for other behaviours. Floating windows are ignored by this method.
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::InitiallyPlace( ZWindow* aWindow )
- {
- Rect wBorder;
- short gh, gv;
-
- FailNILParam( aWindow );
-
- if ( ! aWindow->Floats())
- {
- aWindow->GetStructureFrameBorder( &wBorder );
-
- gh = globalPlaceLoc.h + wBorder.left;
- gv = globalPlaceLoc.v + wBorder.top;
-
- aWindow->PlaceAt( gh, gv );
-
- globalPlaceLoc.h += wBorder.left + 2;
- globalPlaceLoc.v += wBorder.top + 2;
- }
- }
-
-
- /*---------------------------------*** HIDEWINDOW ***---------------------------------*/
- /*
- make the window invisible to the user. Does not change its front-to-back ordering unless
- it was the top one in its layer, in which case the one below it is selected.
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::HideWindow( ZWindow* aWindow )
- {
- FailNILParam( aWindow );
-
- ShowHide( aWindow->GetMacWindow(), FALSE );
- HiliteWindow( aWindow->GetMacWindow(), FALSE );
-
- // if this was the top window, select the next none-hidden one
-
- if ( aWindow->Floats())
- {
- if ( aWindow == GetTopFloater() &&
- floaters->CountItems() > 1 )
- {
- aWindow = floaters->GetObject( 2 );
-
- if ( aWindow && aWindow->IsVisible())
- SelectWindow( aWindow );
- }
- }
- else
- {
- if ( aWindow == GetTopWindow() &&
- nonFloaters->CountItems() > 1 )
- {
- aWindow = nonFloaters->GetObject( 2 );
-
- if ( aWindow && aWindow->IsVisible())
- SelectWindow( aWindow );
- }
- }
- }
-
-
- /*---------------------------------*** SHOWWINDOW ***---------------------------------*/
- /*
- make the window visible to the user. Does not change its front-to-back ordering
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::ShowWindow( ZWindow* aWindow )
- {
- FailNILParam( aWindow );
-
- ShowHide( aWindow->GetMacWindow(), TRUE );
-
- if ( aWindow == GetTopWindow() ||
- aWindow == GetTopFloater())
- SelectWindow( aWindow );
- }
-
-
- /*--------------------------------*** SELECTWINDOW ***--------------------------------*/
- /*
- make the window active. This handles the front-to-back ordering and creates the "floating"
- window illusion.
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::SelectWindow( ZWindow* aWindow )
- {
- FailNILParam( aWindow );
-
- // this is where a certain amount of cunning comes in. To "Select" a non-floater, it
- // is actually moved to come behind the bottom floater. Floaters are treated normally.
- // Dialogs can come in front of all windows, though they will be set to non-floating.
-
- ZWindow* zw;
- long i;
-
- // if window is not visible, make it so
-
- if (! aWindow->IsVisible())
- ShowHide( aWindow->GetMacWindow(), TRUE );
-
- // manipulate our lists and the mac window list
-
- if ( aWindow->Floats())
- {
- i = floaters->FindIndex( aWindow );
-
- // move to head of list, if not there already
-
- if ( i > 1 )
- {
- // deactivate current "top"
-
- zw = GetTopFloater();
-
- if ( zw )
- {
- #ifndef _ALL_FLOATERS_ACTIVE
- HiliteWindow( zw->GetMacWindow(), FALSE );
- #endif
-
- zw->Deactivate();
- }
-
- floaters->MoveToFront( i );
- BringBehind( aWindow, NULL );
- }
- // hilite and activate the new "top" window
-
- aWindow->Activate();
- HiliteWindow( aWindow->GetMacWindow(), TRUE );
- }
- else
- {
- i = nonFloaters->FindIndex( aWindow );
-
- // if already on top, do nothing
-
- if ( i > 1 )
- {
- // deactivate the current "top"
-
- zw = GetTopWindow();
-
- if ( zw )
- PostActivation( zw, FALSE );
-
- // move to head of list
-
- nonFloaters->MoveToFront( i );
- }
- // bring window behind the bottom floater, unless it's a dialog, in which
- // case it's put on top of everything
-
- if ( IsDialog( aWindow ))
- {
- Deactivate();
- BringBehind( aWindow, NULL );
- }
- else
- {
- zw = GetBottomFloater();
- BringBehind( aWindow, zw );
- }
-
- // hilite and activate the new "top" window
-
- PostActivation( aWindow, TRUE );
- }
- }
-
-
- /*-----------------------------*** DRAGWINDOWOUTLINE ***------------------------------*/
- /*
- drag the outline of the window and move it when the mouse is released. This replaces the
- toolbox routine DragWindow, and in addition does a nicer job of clipping the outline.
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::DragWindowOutline( ZWindow* aWindow, Point startPt, const short modifiers )
- {
- FailNILParam( aWindow );
-
- // replaces the toolbox DragWindow, because that will bring a window to the front if
- // you let it.
-
- WindowPtr w;
- RgnHandle dragRgn, temp = NULL;
- Rect limitRect;
- long dragOffset;
- GrafPort screenPort;
- GrafPtr savePort;
- Point wPosition;
-
- w = aWindow->GetMacWindow();
-
- // select the window if command key not down
-
- #ifndef _DRAGWINDOW_COMPATIBLE
-
- if (( modifiers & cmdKey ) == 0 &&
- aWindow != GetTopWindow() &&
- aWindow != GetTopFloater())
- {
- SelectWindow( aWindow );
-
- #ifdef _UPDATE_ON_SELECT
-
- ZEventHandler* zEH = gApplication->GetEventHandler();
- zEH->HandleWindowUpdate( w );
-
- #endif
- }
-
- #endif
-
- // get the limit rect
-
- limitRect = (*GetGrayRgn())->rgnBBox;
- InsetRect( &limitRect, 4, 4 );
-
- // get the outline to drag. This is simply a copy of the window's structure region
-
- FailNIL( dragRgn = NewRgn());
-
- CopyRgn(((WindowPeek) w)->strucRgn, dragRgn );
-
- // set up a port in which to drag the outline. We do this to be good citizens,
- // since meddling with the Mac's Window Manager port is tricky to get away with.
-
- GetPort( &savePort );
- OpenPort( &screenPort );
- SetPort( &screenPort );
-
- // make sure we can drag on the whole desktop
-
- screenPort.portRect = (*GetGrayRgn())->rgnBBox;
- SetClip( GetGrayRgn());
- CopyRgn( screenPort.clipRgn, screenPort.visRgn );
-
- // Remove the regions of all windows in front from the clip region, so it is clearer
- // what will happen when the window moves.
-
- FailNIL( temp = NewRgn());
- CalcWindowRgns( aWindow, temp );
- DiffRgn( screenPort.clipRgn, temp, screenPort.clipRgn );
-
- // drag the outline:
-
- dragOffset = DragGrayRgn( dragRgn, startPt, &limitRect, &limitRect, noConstraint, NULL );
-
- // delete our port
-
- ClosePort( &screenPort );
- SetPort( savePort );
-
- // check the window drag wasn't bogus:
-
- if ( dragOffset != 0x80008000 )
- {
- // OK, figure out where the window moved to, and move it there. If the command key
- // is not down, select tha' booga!
-
- SetPort( w );
-
- wPosition = topLeft( w->portRect );
- LocalToGlobal( &wPosition );
- SetPort( savePort );
-
- // if we are exactly compatible with toolbox DragWindow(), then select the window here
-
- #ifdef _DRAGWINDOW_COMPATIBLE
-
- if (( modifiers & cmdKey ) == 0 &&
- aWindow != GetTopWindow() &&
- aWindow != GetTopFloater())
- SelectWindow( aWindow );
-
- #endif
-
- MoveWindow( w, wPosition.h + LoWord( dragOffset ), wPosition.v + HiWord( dragOffset ), FALSE );
- }
- // clean up
-
- DisposeRgn( dragRgn );
-
- if ( temp )
- DisposeRgn( temp );
- }
-
-
- /*-----------------------------------*** SUSPEND ***----------------------------------*/
- /*
- application is suspending- hide the floaters
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::Suspend()
- {
- // the application is being suspended, so all floaters should be hidden
-
- ZWindow* aFloater;
- ZWindow* tw;
- short i;
-
- tw = GetTopWindow();
-
- if ( tw && !IsDialog( tw ))
- Deactivate();
-
- for (i = 1; i <= floaters->CountItems(); i++)
- {
- aFloater = floaters->GetObject( i );
-
- if ( aFloater )
- ShowHideFloater( aFloater, TRUE );
- }
-
- #ifndef _ACTIVATE_EVENTS_ARE_REAL
- // actually send deactivate event to top window
-
- if ( tw )
- PostActivation( tw, FALSE );
- #endif
- }
-
- /*-----------------------------------*** RESUME ***-----------------------------------*/
- /*
- application is resuming- show the floaters
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::Resume()
- {
- // the application is being resumed, so all floaters should be re-shown.
-
- ZWindow* aFloater;
- ZWindow* tw;
- short i;
-
- for (i = 1; i <= floaters->CountItems(); i++)
- {
- aFloater = floaters->GetObject( i );
-
- if ( aFloater )
- ShowHideFloater( aFloater, FALSE );
- }
-
- tw = GetTopWindow();
-
- if (tw && !IsDialog( tw ))
- Activate();
-
- #ifndef _ACTIVATE_EVENTS_ARE_REAL
- // actually send activate event to top window
-
- if ( tw )
- PostActivation( tw, TRUE );
- #endif
- }
-
- /*---------------------------------*** DEACTIVATE ***---------------------------------*/
- /*
- a modal dialog is coming up, so deactivate all floaters and the top window. You need to
- call this whenever you put up a non ZDialog-based dialog, such as standard file, for
- consistent behaviour with MacZoop dialogs. Those objects will call this automatically.
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::Deactivate()
- {
- // a dialog is up, so all floaters plus the top window must be deactivated
-
- ZWindow* zw;
-
- #ifndef _ALL_FLOATERS_ACTIVE
-
- zw = GetTopFloater();
-
- if ( zw )
- PostActivation( zw, FALSE );
-
- #else
-
- short i;
-
- for (i = 1; i <= floaters->CountItems(); i++ )
- {
- zw = floaters->GetObject( i );
-
- if ( zw )
- PostActivation( zw, FALSE );
- }
-
- #endif
-
-
- zw = GetTopWindow();
-
- if ( zw )
- PostActivation( zw, FALSE );
- }
-
-
- /*----------------------------------*** ACTIVATE ***----------------------------------*/
- /*
- the modal dialog is going away, so reactivate the floaters and top window
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::Activate()
- {
- // a dialog is going away, so all floaters plus the top window must be reactivated
-
- ZWindow* zw;
-
- #ifndef _ALL_FLOATERS_ACTIVE
-
- zw = GetTopFloater();
-
- if ( zw )
- PostActivation( zw, TRUE );
-
- #else
-
- short i;
-
- for (i = 1; i <= floaters->CountItems(); i++ )
- {
- zw = floaters->GetObject( i );
-
- if ( zw )
- PostActivation( zw, TRUE );
- }
-
- #endif
-
- zw = GetTopWindow();
-
- if ( zw && ! IsDialog( zw ))
- PostActivation( zw, TRUE );
- }
-
-
- /*--------------------------------*** GETTOPWINDOW ***--------------------------------*/
- /*
- get uppermost non-floating window
- ----------------------------------------------------------------------------------------*/
-
- ZWindow* ZWindowManager::GetTopWindow()
- {
- // returns the top non-floating window
-
- if ( nonFloaters->CountItems() > 0 )
- return nonFloaters->GetObject( 1 );
- else
- return NULL;
- }
-
-
- /*-------------------------------*** GETTOPFLOATER ***--------------------------------*/
- /*
- get uppermost floating window
- ----------------------------------------------------------------------------------------*/
-
- ZWindow* ZWindowManager::GetTopFloater()
- {
- // returns the top floating window
-
- if ( floaters->CountItems() > 0 )
- return floaters->GetObject( 1 );
- else
- return NULL;
- }
-
-
- /*------------------------------*** GETBOTTOMFLOATER ***------------------------------*/
- /*
- get the last window in the floating layer. Top window is the one behind this.
- ----------------------------------------------------------------------------------------*/
-
- ZWindow* ZWindowManager::GetBottomFloater()
- {
- // returns the bottom-most floater
-
- if ( floaters->CountItems() > 0 )
- return floaters->GetObject( floaters->CountItems());
- else
- return NULL;
- }
-
-
- /*------------------------------*** CHECKDIALOGEVENT ***------------------------------*/
- /*
- determine if the event is aimed at a dialog. This replaces the toolbox IsDialogEvent call
- such that it does not call FrontWindow().
- ----------------------------------------------------------------------------------------*/
-
- Boolean ZWindowManager::CheckDialogEvent( EventRecord* theEvent )
- {
- // the event is for a dialog if the window kind explicitly passed with certain events is
- // a dialog, or for other events, that the top window as we know it is a dialog.
-
- WindowPeek w;
- Boolean result = FALSE;
- ZWindow* zw;
-
- // is this a window explicit event?
-
- if ( theEvent->what == updateEvt ||
- theEvent->what == activateEvt )
- {
- // yes, so get the window and see if it's a dialog
-
- w = (WindowPeek) theEvent->message;
-
- result = ( w->windowKind == dialogKind );
- }
- else
- {
- // is the event a mouse down? If so we need to see if it was in the active dialog
- // window.
-
- if ( theEvent->what == mouseDown )
- {
- short part = FindWindow( theEvent->where, (WindowPtr*) &w );
-
- zw = GetTopWindow();
-
- result = ( part == inContent &&
- w->windowKind == dialogKind &&
- zw &&
- zw->GetMacWindow() == (WindowPtr) w );
- }
- else
- {
- zw = GetTopWindow();
-
- // we do our own checks but also call the toolbox IsDialogEvent, so that
- // ballon help in dialogs is correctly displayed. (Balloon help hooks into
- // this routine to provide dialog balloons).
-
- result = ( zw &&
- ((WindowPeek) zw->GetMacWindow())->windowKind == dialogKind &&
- IsDialogEvent( theEvent ));
- }
- }
- return result;
- }
-
-
- /*--------------------------------*** LOCATEWINDOW ***--------------------------------*/
- /*
- find the window under the mouse, or NULL if none are
- ----------------------------------------------------------------------------------------*/
-
- ZWindow* ZWindowManager::LocateWindow( const Point globalMouse )
- {
- WindowPeek w;
- ZWindow* zw = NULL;
-
- w = ( WindowPeek ) FrontWindow();
-
- while ( w )
- {
- if ( PtInRgn( globalMouse, w->strucRgn ))
- {
- zw = GetZWindow(( WindowPtr ) w );
- break;
- }
-
- w = w->nextWindow;
- }
-
- return zw;
- }
-
-
- /*--------------------------------*** GETNTHWINDOW ***--------------------------------*/
- /*
- return the window <n>, or NULL if bad index
- ----------------------------------------------------------------------------------------*/
-
- ZWindow* ZWindowManager::GetNthWindow( const long n )
- {
- ZWindow* zw = NULL;
-
- try
- {
- zw = nonFloaters->GetObject( n );
- }
- catch( OSErr err )
- {
- }
-
- return zw;
- }
-
-
- /*--------------------------------*** GETNTHFLOATER ***-------------------------------*/
- /*
- return the floating window <n>, or NULL if bad index
- ----------------------------------------------------------------------------------------*/
-
- ZWindow* ZWindowManager::GetNthFloater( const long n )
- {
- ZWindow* zw = NULL;
-
- try
- {
- zw = floaters->GetObject( n );
- }
- catch( OSErr err )
- {
- }
-
- return zw;
- }
-
-
- /*----------------------------------*** ISDIALOG ***----------------------------------*/
- /*
- is the window a modal dialog?
- ----------------------------------------------------------------------------------------*/
-
- Boolean ZWindowManager::IsDialog( ZWindow* aWindow )
- {
- // return TRUE if the window is a modal dialog (but not for modeless ones)
-
- ZDialog* zd = dynamic_cast<ZDialog*> ( aWindow );
-
- if (zd && zd->IsModal())
- return TRUE;
- else
- return FALSE;
- }
-
-
- /*--------------------------*** GETUNIQUEUNTITLEDNAME ***-----------------------------*/
- /*
- as part of the human interface guidelines adherence, we automatically name new windows
- untitled, untitled 1, etc. This method scans through the names of all the windows in the
- main list (ignores floaters), making sure the name is unique. If not, it appends 1, 2, etc
- until the name is unique. If the name was unique, it returns FALSE, otherwise TRUE. i.e.
- TRUE means we modified the name. Uses EqualString to compare names, ignores case.
- ----------------------------------------------------------------------------------------*/
-
- Boolean ZWindowManager::GetUniqueUntitledName( Str255 wName )
- {
- short n = 1, i;
- Boolean result = FALSE, match;
- Str255 sName, temp;
- ZWindow* zw;
-
- CopyPString( wName, temp );
-
- do
- {
- match = FALSE;
-
- for ( i = 1; i <= nonFloaters->CountItems(); i++ )
- {
- zw = nonFloaters->GetObject( i );
- zw->GetName( sName );
-
- if ( EqualString( temp, sName, FALSE, FALSE ))
- {
- match = TRUE;
- break;
- }
- }
-
- if ( match )
- {
- // the name matched some window, so append a digit and try again
-
- CopyPString( wName, temp );
-
- NumToString( n++, sName );
- ConcatPStrings( temp, "\p " );
- ConcatPStrings( temp, sName );
- }
- else
- {
- result = TRUE;
- CopyPString( temp, wName );
- }
- }
- while( ! result );
-
- return result;
- }
-
-
- /*----------------------------------*** FLOATIDLE ***---------------------------------*/
- /*
- pass idle to each floater, in case they do periodic action
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::FloatIdle()
- {
- long i;
- ZWindow* aFloater;
-
- for( i = 1; i <= floaters->CountItems(); i++ )
- {
- aFloater = floaters->GetObject( i );
-
- if ( aFloater )
- aFloater->Idle();
- }
- }
-
-
- /*---------------------------------*** COUNTWINDOWS ***-------------------------------*/
- /*
- return the number of non-floating windows the manager knows about
- ----------------------------------------------------------------------------------------*/
-
- short ZWindowManager::CountWindows()
- {
- return nonFloaters->CountItems();
- }
-
- /*---------------------------------*** COUNTFLOATERS ***------------------------------*/
- /*
- return the number of floating windows the manager knows about
- ----------------------------------------------------------------------------------------*/
-
- short ZWindowManager::CountFloaters()
- {
- return floaters->CountItems();
- }
-
-
- /*--------------------------------*** SETWINDOWSMENU ***------------------------------*/
- /*
- sets the passed menu to be the application's "Windows" menu. Called by ZMenuBar- do not
- call this method directly- use gMenuBar->NominateWindowsMenu() instead. This should be
- called before any non-floating windows are created.
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::SetWindowsMenu( MenuHandle aMenu )
- {
- FailNILParam( aMenu );
-
- wmMenu = aMenu;
- wmItemOffset = CountMenuItems( aMenu );
-
- // make a list to keep an ordered list of windows that does not depend on
- // the front-to-back order
-
- FailNIL( wmWindows = new ZWindowList());
-
- BuildWindowsMenu();
- }
-
-
- /*-----------------------------*** SELECTWINDOWFROMMENU ***---------------------------*/
- /*
- called only by the main menubar to select the window from the menu. Do not call this
- yourself.
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::SelectWindowFromMenu( const short itemID )
- {
- if ( wmMenu && wmWindows && !IsDialog( GetTopWindow()))
- {
- short n = itemID - wmItemOffset;
-
- if ( wmItemOffset > 0 )
- n--; // allow for divider line
-
- if (( n > 0 ) && ( n <= wmWindows->CountItems()))
- {
- ZWindow* zw = wmWindows->GetObject( n );
-
- if ( zw )
- zw->Select();
- }
- }
- }
-
-
- #pragma mark -
-
- /*---------------------------------*** BRINGBEHIND ***--------------------------------*/
- /*
- change the window ordering so it is behind another. If behindWindow is NULL, window is
- brought to the front.
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::BringBehind( ZWindow* aWindow, ZWindow* behindWindow )
- {
- // brings <aWindow> behind <behindWindow>. If <behindWindow> is NULL, it is brought
- // to the front. This manipulates the mac windowlist to match the state here.
-
- WindowPtr a, b;
-
- if ( behindWindow )
- {
- a = aWindow->GetMacWindow();
- b = behindWindow->GetMacWindow();
-
- SendBehind( a, b );
- }
- else
- BringToFront( aWindow->GetMacWindow());
- }
-
-
- /*-------------------------------*** POSTACTIVATION ***-------------------------------*/
- /*
- simulate an activation event for the window
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::PostActivation( ZWindow* aWindow, Boolean state )
- {
- // posts an activate event for the window. This will be picked up by the event handler, which
- // will then maintain the command chain correctly. Floater activations are never sent in this
- // way, but their activate methods are called directly.
-
- HiliteWindow( aWindow->GetMacWindow(), state );
-
- if ( aWindow->Floats())
- {
- if ( state )
- aWindow->Activate();
- else
- aWindow->Deactivate();
- }
- else
- {
-
- #ifdef _ACTIVATE_EVENTS_ARE_REAL
-
- EvQElPtr evQ;
-
- if ( aWindow )
- {
- long evtMessage = (long) aWindow->GetMacWindow();
-
- FailOSErr( PPostEvent( activateEvt, evtMessage, &evQ ));
-
- // set up the modifiers to indicate activation state
-
- if ( state )
- evQ->evtQModifiers |= activeFlag;
- else
- evQ->evtQModifiers &= ~activeFlag;
- }
-
- #else
-
- ZEventHandler* ze = gApplication->GetEventHandler();
-
- ze->HandleWindowActivate( aWindow->GetMacWindow(), state );
-
- #endif
- }
- }
-
-
- /*------------------------------*** CALCWIONDOWRGNS ***-------------------------------*/
- /*
- calculate the union of the window structure regions in front of the window. This is used
- to build a clip region for window dragging.
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::CalcWindowRgns( ZWindow* aWindow, RgnHandle aRgn )
- {
- // sets <theRgn> to the union of all windows in front if <aWindow>, including floaters.
- // This is used to form the clip region for a window drag. Note- this doesn't check the
- // parameters for sanity.
-
- SetEmptyRgn( aRgn );
-
- // the simplest way to achieve this is to scan the real mac window list, since that
- // allows us to treat the window ordering simply without consideration of our separate
- // lists.
-
- WindowPeek w = (WindowPeek) FrontWindow();
-
- while (w && w != (WindowPeek) aWindow->GetMacWindow())
- {
- UnionRgn( w->strucRgn, aRgn, aRgn );
-
- w = w->nextWindow;
- }
- }
-
-
- /*------------------------------*** SHOWHIDEFLOATER ***-------------------------------*/
- /*
- show or hide a floater by moving it offscreen.
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::ShowHideFloater( ZWindow* aFloater, Boolean hide )
- {
- FailNILParam( aFloater );
-
- short dh = 10000;
- Point wLoc;
- WindowPtr w = aFloater->GetMacWindow();
- Rect dtBounds = (*GetGrayRgn())->rgnBBox;
-
- if (! hide)
- dh = -dh;
-
- wLoc = topLeft( w->portRect );
-
- aFloater->Focus();
- LocalToGlobal( &wLoc );
-
- // don't attempt to hide or show more than once- it doesn't work. To this end we check
- // that the window is not already positioned
-
- if (( hide && wLoc.h < dtBounds.right ) ||
- ( ! hide && wLoc.h > dtBounds.right ))
- MoveWindow( w, wLoc.h + dh, wLoc.v, FALSE );
- }
-
-
- /*-----------------------------*** BUILDWINDOWSMENU ***-------------------------------*/
- /*
- fill menu with current list of windows, and check current one.
- ----------------------------------------------------------------------------------------*/
-
- void ZWindowManager::BuildWindowsMenu()
- {
- short n, i, mi;
-
- if ( wmMenu )
- {
- // delete items beyond initial number
-
- n = CountMenuItems( wmMenu );
-
- while( n > wmItemOffset )
- DeleteMenuItem( wmMenu, n-- );
-
- // set menu to window titles. If the offset was >0, add a dividing line first
-
- if ( wmWindows )
- {
- ZWindow* zw;
- Str255 title;
-
- n = wmWindows->CountItems();
-
- if (( wmItemOffset > 0 ) && ( n > 0 ))
- AppendMenu( wmMenu, "\p-" );
-
- for( i = 1; i <= n; i++ )
- {
- mi = i + wmItemOffset;
-
- if ( wmItemOffset > 0 )
- mi++; // allow for extra divider line
-
- zw = wmWindows->GetObject( i );
-
- zw->GetName( title );
-
- AppendMenu( wmMenu, "\px" );
- SetMenuItemText( wmMenu, mi, title );
- EnableItem( wmMenu, mi );
-
- // if window is active, check that item
-
- if ( zw == GetTopWindow())
- CheckItem( wmMenu, mi, TRUE );
- }
- }
- }
- }
-
-
-